package com.wxy.demo.kafka;

import org.apache.kafka.clients.admin.*;

import java.util.*;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 *
 * </p>
 *
 * @author e-Xiaoyuan.Wang
 * @since 2022/11/8 18:34
 */
public class AdminDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Properties props = new Properties();
        props.put("bootstrap.servers", "10.168.40.54:9092");
        AdminClient client = AdminClient.create(props);

        // 创建topic
        NewTopic newTopic = new NewTopic("topic1", 4, (short) 1);
        CreateTopicsResult result = client.createTopics(Arrays.asList(newTopic));
        result.all().get();

        // 删除topic
//        DeleteTopicsResult result1 = client.deleteTopics(Arrays.asList("topic1"));
//        result1.all().get();

        // 查询所有topic
        Set<String> set = client.listTopics().names().get();
        System.out.println(set);

        // 修改分区
//        Map<String, NewPartitions> newPartitions = new HashMap<>();
//        newPartitions.put("topic1", NewPartitions.increaseTo(4));
//        CreatePartitionsResult result2 = client.createPartitions(newPartitions);
//        result2.all().get();
    }
}
